package cn.wyl.tran;

import org.apache.rocketmq.client.producer.LocalTransactionState;
import org.apache.rocketmq.client.producer.TransactionListener;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;

public class TranListener implements TransactionListener {
    @Override
    public LocalTransactionState executeLocalTransaction(Message message, Object o) {
        //执行业务，保存本地事务
        System.out.println("本地mysql数据库包含用户数据成功");
        System.out.println(o.toString());

        //保存成功
        return LocalTransactionState.COMMIT_MESSAGE ; //ROLLBACK_MESSAGE;    //未知

        //不返回事务状态
        //return LocalTransactionState.UNKNOW ;
    }

    @Override
    public LocalTransactionState checkLocalTransaction(MessageExt messageExt) {
        //这里查询本地事务状态
        System.out.println("检查本地mysql有没有保存用户成功");
        //假设没成功
        return LocalTransactionState.COMMIT_MESSAGE;
    }
}
